package j2seperf.io;

import java.io.*;

public class FastCopyFile {

	public static void copy(String from, String to) throws IOException {
		InputStream in = null;
		OutputStream out = null;
		try {
			InputStream inFile = new FileInputStream(from);
			in = new BufferedInputStream(inFile);
			OutputStream outFile = new FileOutputStream(to);
			out = new BufferedOutputStream(outFile);
			while (true) {
				int data = in.read();
				if (data == -1) {
					break;
				}
				out.write(data);
			}
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.close();
			}
		}
	}

	public static void main(String[] args) {
		try {
			Stopwatch timer = new Stopwatch().start();
			for (int i = 0; i < 20; i++) {
				copy("o.dat", "output.dat");
			}
			timer.stop();
			System.out.println(timer.getElapsedTime() / 20);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
